$(function () {
	//初始页数
	var page = 1;
	//加载更多
	$("#tomore").click(function() {
		var t = $('.diaryTitle-frTab-liActive').text();
		var industry = t == '全部'?null:t;
		//异步加载作者
		$.ajax({ 
			 url: '/industry/screen', 
			 type: "GET",
	        data: {industry: industry,page: page},
	        dataType: "json",//请求数据类型
			 success: function(data){
				 if(data.code == 0){
					 var count = data.count;
					 if(count > 0){
						 var result = data.data;
						 $("#authorlist").append(result);
						 page++;
						 if(count < 19){
							 $('.LoadMore').empty();
							 $('.LoadMore').text('没有更多加载了');
						 }
						 $(".authorTent-followA").off("click").on("click",function(){
							var that = $(this);
							var authorid = that.data('authorid');
							var userid = $("#userid").data("userid");
							if(userid != ''){
								 if(that.hasClass('authorTent-iActive') || that.hasClass('authorTent-iMutual')){
									 $.ajax({ 
										 url: '/operate/'+ userid + '/cancel/' + authorid, 
										 type: "POST",
								         data: {},
								         dataType: "json",//请求数据类型
										 success: function(data){
											 var result = data.data;
											 if(data.code == 0){
										        that.removeClass("authorTent-iActive");
										        that.removeClass("authorTent-iMutual");
										        that.text("+关注")
										        var num = Number($('#F' + authorid).text());
										        $('#F' + authorid).text(num-1);
											 }else{
												 layer.msg(data.msg);
											 }
										 },
										 error : function() {
											 layer.msg("取消关注异常");
										 }
									 })	
								}else{
									$.ajax({ 
										 url: '/operate/'+ userid + '/follow/' + authorid, 
										 type: "POST",
								         data: {},
								         dataType: "json",//请求数据类型
										 success: function(data){
											 var result = data.data;
											 if(data.code == 0){
												 if(result == 1){
														that.addClass("authorTent-iActive");
												        that.text("✓已关注")
													 }else if(result == 2){
														 that.addClass("authorTent-iMutual");
													     that.text("⇋互为关注")
													 }
													 var num = Number($('#F' + authorid).text());
												     $('#F' + authorid).text(num+1);
											 }else{
												 layer.msg(data.msg);
											 }
										 },
										 error : function() {
											 layer.msg("关注失败");
										 }
									 })
								}
								
							}else{
								window.location.href = "/signup"
							}
						})
					 }else{
						 $('.LoadMore').empty();
						 $('.LoadMore').text('没有更多加载了');
					 }
				 }else{
					 $('.LoadMore').empty();
					 $('.LoadMore').text(data.msg);
				 }
			 },
			 error : function() {
				 $('.LoadMore').empty();
				 $('.LoadMore').text('加载失败');
			 }
		 })
	});
	
});